/*	Renegade Scripts.dll
	Scripts by SLA.RO - sla company
	Copyright 2010 SLA.RO

	This file is part of the Renegade scripts.dll
	The Renegade scripts.dll is free software; you can redistribute it and/or modify it 
	under the terms of the GNU General Public License as published by the Free
	Software Foundation; either version 2, or (at your option) any later
	version. See the file COPYING for more details.
	In addition, an exemption is given to allow Run Time Dynamic Linking of this code 
	with any closed source module that does not contain code covered by this licence.
	Only the source code to the module(s) containing the licenced code has to be released.
*/

#include "scripts.h"
#include "engine.h"
#include "sla.h"

 // Some Global Commands used for COOP

void sla_enter_cmsg_gdi::Entered(GameObject *obj,GameObject *enter)
{
	const char *message;
	message = Get_Parameter("Message");//any USER input requests go between those commas
	Send_Message(255,204,0,message);
	Destroy_Script();
}

void sla_enable_poke::Created(GameObject *obj)
{
	Commands->Enable_HUD_Pokable_Indicator(obj, true);
	Destroy_Script();
}



void sla_poke_cmsg_gdi::Poked(GameObject *obj,GameObject *poker)
{
    Commands->Enable_HUD_Pokable_Indicator(obj, false);
	const char *message;
	message = Get_Parameter("Message");//any USER input requests go between those commas
	Send_Message(255,204,0,message);
	Destroy_Script();
}

void sla_poke_distroy_obj::Poked(GameObject *obj,GameObject *poker)
{
	Commands->Enable_HUD_Pokable_Indicator(obj, false);
    Commands->Destroy_Object(Commands->Find_Object(Get_Int_Parameter("ID")));
	Destroy_Script();
}

void sla_enter_play_sound::Entered(GameObject *obj,GameObject *enter)
{
	const char *SoundFile;
	SoundFile = Get_Parameter("SoundFile");
	Commands->Create_2D_WAV_Sound(SoundFile);
	Destroy_Script();
}

void sla_poke_play_sound::Poked(GameObject *obj,GameObject *poker)
{
	const char *SoundFile;
	SoundFile = Get_Parameter("SoundFile");
	Commands->Create_2D_WAV_Sound(SoundFile);
	Destroy_Script();
}


void sla_enter_cmsg_nod::Entered(GameObject *obj,GameObject *enter)
{
	const char *message;
	message = Get_Parameter("Message");//any USER input requests go between those commas
	Send_Message(255,204,0,message);
	Destroy_Script();
}

void sla_enter_send_message::Created(GameObject *obj)
{
	sendmsg = true;
	id = Get_Int_Parameter("ID");
	msg = Get_Int_Parameter("Message");
	prm = 1;
	delay = Get_Float_Parameter("Delay");
}
void sla_enter_send_message::Entered(GameObject *obj, GameObject *enter)
{
	if (sendmsg)
	{
		sendmsg = false;//if we dont do this ppl can trigger it mutliple times when entering the zoneok
		Commands->Start_Timer(obj,this,0.1,100);
	}
}

void sla_enter_send_message::Timer_Expired(GameObject *obj, int number)
{
	if (number == 100)
	{
		Commands->Send_Custom_Event(obj,Commands->Find_Object(id),msg,prm,0);
		Destroy_Script();
	}
}
void sla_enter_send_message::Register_Auto_Save_Variables()
{
	Auto_Save_Variable(1,5,&sendmsg);
	Auto_Save_Variable(1,5,&id);
	Auto_Save_Variable(1,5,&msg);
	Auto_Save_Variable(1,5,&prm);
	Auto_Save_Variable(1,5,&delay);
}

void sla_m05_endgame::Custom(GameObject *obj, int message, int param, GameObject *sender)
{
	if (message == 1000)
	{
		if (param == 1)
		{
			Commands->Start_Timer(obj,this,0.5f,100);//well done msg
		}
	}
}
void sla_m05_endgame::Timer_Expired(GameObject *obj, int number)
{
	if (number == 100)
	{
		Commands->Create_2D_WAV_Sound("m00_wins0002eval_snd.wav");
		Send_Message(255,204,0,"Well Done Havoc.");
		//well done havoc + sound
		Commands->Start_Timer(obj,this,2.5f,101);//do next sound
	}
	else if (number == 101)
	{
		Commands->Create_2D_WAV_Sound("m00_wins0001evag_snd.wav");
		Send_Message(255,204,0,"Mission Accomplished!");
		//mission accomplsihed + sound
		Commands->Start_Timer(obj,this,2.5f,102);//gameover, ok your turn :) ok..
	}
	else if (number == 102)
	{
		Console_Input("win 1");//now we end the game after players been informed of mission accomplshed... YOU script the rest lol? me ? lol ok.... i need to find sounds ,lol
	}
}

//sigh where to start, its best to do this as the mission is beign made >.<
// hmmm... idk.. lol
// 

void sla_M05_Checkpoint1::Created(GameObject *obj)
{
	tele = false;//ppl may not teleport when its created, obivously 
	allowpoke = true;//they may poke the object
	gotoid1 = Get_Int_Parameter("GotoID1");
	gotoid2 = Get_Int_Parameter("GotoID2");
	gotoid3 = Get_Int_Parameter("GotoID3");
	gotoid4 = Get_Int_Parameter("GotoID4");
	gotoid5 = Get_Int_Parameter("GotoID5");//get your input in leveledit for the dave arrow id's to teleport to...
}
void sla_M05_Checkpoint1::Poked(GameObject *obj, GameObject *poker)//when the object is poked do this
{
	if (allowpoke)//is poking E allowed?
	{
		if (tele)//is teleporting allowed?
		{
			int random = Commands->Get_Random_Int(1,2);//get a random value between 1 and 5,to determine which gotoid* to teleport to
			if (random == 1)
			{
				Vector3 gotoloc1 = Commands->Get_Position(Commands->Find_Object(gotoid1));//here wer get the pos of the place to goto, the id of arrow ok
				Commands->Set_Position(poker,gotoloc1);//you understand this? yep
			}
			else if (random == 2)
			{
				Vector3 gotoloc2 = Commands->Get_Position(Commands->Find_Object(gotoid2));//here wer get the pos of the place to goto, the id of arrow ok
				Commands->Set_Position(poker,gotoloc2);//you understand this? yep
			}// ok... :D  now repeat until random == 5
		}
		else //not alowed
		{
			Send_Message(255,204,0,"Access Denied");
			Commands->Create_2D_WAV_Sound("accessdenied.wav");
		}
		allowpoke = false;//disable poking temporarily
		Commands->Start_Timer(obj,this,2.5f,100);//enable poking again, this way people cant teleport at te same time and get stuck in eouch otherlol
	}
}
void sla_M05_Checkpoint1::Timer_Expired(GameObject *obj, int number)
{
	if (number == 100)//the enable poking timer
	{
		allowpoke = true;//yep they can poke again now..
	}
	else if (number == 101)//announce cp open
	{
		//gunner was poked, objective complete...
		//in other words we need a script for gunner that will send a msg once to this script...(obj that has this script on it)
		Send_Message(255,204,0,"Objective Completed!");
		Commands->Create_2D_WAV_Sound("incmsg.wav");
	}
}
void sla_M05_Checkpoint1::Custom(GameObject *obj, int message, int param, GameObject *sender)
{
	//if we receive our message we define then unlock the teleporter so tele=true
	if (message == 1000)//send message 1000,1 to this object to enable the teleporter, so if they complete an objective send msg 1000 with param 1 and the tele opens up...
	{
		if (param == 1)
		{
			//ok as soon as we receive our msg 1000 and param 1 we start a timer 101 of 0.1 seconds to immideatly tell the players
			//that thye COMPLETED a objective FIRST
			Commands->Start_Timer(obj,this,0.1f,101);//announce secondary objective met..
		}
	}
}
void sla_M05_Checkpoint1::Register_Auto_Save_Variables()
{
	Auto_Save_Variable(1,5,&allowpoke);
	Auto_Save_Variable(1,5,&tele);//the bool checks must be savesd...
}

void sla_M05_Gunner::Created(GameObject *obj)
{
	allowpoke = true;
}
void sla_M05_Gunner::Poked(GameObject *obj, GameObject *poker)
{
	if (allowpoke)
	{
		allowpoke = false;
		Commands->Send_Custom_Event(obj,Commands->Find_Object(Get_Int_Parameter("SendID")),1000,1,0);//in leveledit just enter the id of the poke terminal to unlock the teleporter... ok..
	}
}

void sla_poke_send_custom::Poked(GameObject *obj, GameObject *poker)
{
	int sendider = Get_Int_Parameter("SendID");
	Commands->Send_Custom_Event(obj,Commands->Find_Object(sendider),Get_Int_Parameter("Message"),Get_Int_Parameter("Param"),0);		
	Destroy_Script();
}

void sla_enable_poke_delay::Created(GameObject *obj){
delay = Get_Float_Parameter("Delay");
}

void sla_enable_poke_delay::Poked(GameObject *obj, GameObject *poker){
  Commands->Enable_HUD_Pokable_Indicator(obj, false);
  Commands->Start_Timer(obj,this,delay,100);
}

void sla_enable_poke_delay::Timer_Expired(GameObject *obj, int number)
{
 Commands->Enable_HUD_Pokable_Indicator(obj, true);
}

// This script is the best :P , i hope it works :D
void sla_teleportconsole::Created(GameObject *obj)
{
	teleport = false;
	wait = false;
	getmessage = Get_Int_Parameter("GetMessage");
	getmessage2 = Get_Int_Parameter("GetMessageBlock");
	getparam = Get_Int_Parameter("GetParam");
	teleport1 = Get_Int_Parameter("Teleport1");
	teleport2 = Get_Int_Parameter("Teleport2");
	delaytime = Get_Float_Parameter("Delay");
	Commands->Enable_HUD_Pokable_Indicator(obj, true);
	// this script can be used on a console for teleport , it using poke and only if delay and teleport = true :P
}

void sla_teleportconsole::Poked(GameObject *obj, GameObject *poker)
{
	 if (wait == false){
	  if (teleport == false){
		  Send_Message(255,204,0,"Access Denied!");
			Commands->Create_2D_WAV_Sound("accessdenied.wav");
			Commands->Enable_HUD_Pokable_Indicator(obj, false);
			wait = true;
			Commands->Start_Timer(obj,this,delaytime,100);
	  }
	  else {
		  	// random teleport player...
			int random = Commands->Get_Random_Int(1,2);//get a random value between 1 and 5,to determine which gotoid* to teleport to
			if (random == 1)
			{
				Vector3 gotoloc1 = Commands->Get_Position(Commands->Find_Object(teleport1));//here wer get the pos of the place to goto, the id of arrow ok
				Commands->Set_Position(poker,gotoloc1);//you understand this? yep
			}
			else if (random == 2)
			{
				Vector3 gotoloc2 = Commands->Get_Position(Commands->Find_Object(teleport2));//here wer get the pos of the place to goto, the id of arrow ok
				Commands->Set_Position(poker,gotoloc2);//you understand this? yep
			}
		  Commands->Start_Timer(obj,this,delaytime,100);
		  Commands->Enable_HUD_Pokable_Indicator(obj, false);
			wait = true;
	  }
	 }
	else {


	}
}

void sla_teleportconsole::Timer_Expired(GameObject *obj, int number)
{
	if (number == 100)
	{
		wait = false;
		Commands->Enable_HUD_Pokable_Indicator(obj, true);
	}

}

void sla_teleportconsole::Custom(GameObject *obj, int message, int param, GameObject *sender){
 if (message == getmessage){
	  teleport = true;
 }

  if (message == getmessage2){
	  teleport = false;
 }
}


// some delay stuff and others..

void sla_death_cmsg_delay::Created(GameObject *obj)
{
	make = false;
	delay = Get_Float_Parameter("Delay");
}

void sla_death_cmsg_delay::Killed(GameObject *obj,GameObject *shooter)
{

		Commands->Start_Timer(obj,this,delay,10);
}

void sla_death_cmsg_delay::Timer_Expired(GameObject *obj, int number)
{
	if (number == 10) {
	const char *message;
	message = Get_Parameter("Message");
	Send_Message(255,204,0,message);
	Destroy_Script();
	}
}

void sla_poke_gameover::Poked(GameObject *obj, GameObject *poker)
{
	Commands->Start_Timer(obj,this,2.5f,100);
}

void sla_poke_gameover::Timer_Expired(GameObject *obj, int number)
{
	if (number == 100)
	{
		Commands->Create_2D_WAV_Sound("m00_wins0002eval_snd.wav");
		Send_Message(255,204,0,"Well Done Havoc.");
		Commands->Start_Timer(obj,this,2.5f,101);
	}
	else if (number == 101)
	{
		Commands->Create_2D_WAV_Sound("m00_wins0001evag_snd.wav");
		Console_Input("amsg Mission Accompished!");
		Console_Input("gameover");
		Destroy_Script();
	}
}


// M05
ScriptRegistrant<sla_M05_Gunner>sla_M05_Gunner_Registrant("sla_M05_Gunner","SendID=1:int");
ScriptRegistrant<sla_M05_Checkpoint1> sla_M05_Checkpoint1_Registrant("sla_M05_Checkpoint1","GotoID1=1:int,GotoID2=2:int");
ScriptRegistrant<sla_m05_endgame> sla_m05_endgame_Registrant("sla_m05_endgame","");

// Global without delay
ScriptRegistrant<sla_enter_send_message> sla_enter_send_message_Registrant("sla_enter_send_message","Message=1000:int,ID=1:int,Delay=5:float");
ScriptRegistrant<sla_enter_cmsg_gdi> sla_enter_cmsg_gdi_Registrant("sla_enter_cmsg_gdi","Message=message:string");
ScriptRegistrant<sla_enter_cmsg_nod> sla_enter_cmsg_nod_Registrant("sla_enter_cmsg_nod","Message=message:string");
ScriptRegistrant<sla_poke_cmsg_gdi> sla_poke_cmsg_gdi_Registrant("sla_poke_cmsg_gdi","Message=message:string");
ScriptRegistrant<sla_enable_poke> sla_enable_poke_Registrant("sla_enable_poke","");
ScriptRegistrant<sla_poke_distroy_obj> sla_poke_distroy_obj_Registrant("sla_poke_distroy_obj","ID=0:int");
ScriptRegistrant<sla_enter_play_sound> sla_enter_play_sound_Registrant("sla_enter_play_sound","SoundFile=sound.wav:string");
ScriptRegistrant<sla_poke_play_sound> sla_poke_play_sound_Registrant("sla_poke_play_sound","SoundFile=sound.wav:string");
ScriptRegistrant<sla_poke_send_custom> sla_poke_send_custom_Registrant("sla_poke_send_custom_sound_message","SendID=0:int,Message=1000:int,Param=1:int,Sound=mysound.wav:string,DisplayMessage=hello:string");
ScriptRegistrant<sla_poke_gameover> sla_poke_gameover_Registrant("sla_poke_gameover","");


// delayed stuff

ScriptRegistrant<sla_death_cmsg_delay> sla_death_cmsg_delay_Registrant("sla_death_cmsg_delay","Delay=5:float,Message=hi:string");
ScriptRegistrant<sla_enable_poke_delay> sla_enable_poke_delay_Registrant("sla_enable_poke_delay","Delay=5:float");
ScriptRegistrant<sla_teleportconsole> sla_teleportconsole_Registrant("sla_teleportconsole","GetMessage=100:int,GetMessageBlock=100:int,GetParam=1:int,Teleport1=0:int,Teleport2=1:int,Delay=5:float");



